import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {Device} from '../model/Device';
import {Observable} from 'rxjs';

@Injectable()
export class DeviceService {

  constructor(private http: HttpClient) {
  }

  list(): Observable<Device[]> {
    return this.http.get<Device[]>('/device');
  }

  get(id: string): Observable<Device> {
    return this.http.get<Device>('/device/' + id);
  }

  delete(id: string): Observable<object> {
    return this.http.delete('/device/' + id);
  }

  add(device: Device): Observable<object> {
    return this.http.post('/device', device)
  }

  dataChange(message: string): Observable<object> {
    return this.http.post('/notify/dataChange', message, {headers: {"Content-Type": "application/json"}});
  }
}
